<html><head><title>UserGuide - Displaying text output (Console)</title></head>
<body bgcolor="#EFF1F0" link="#3A3966" vlink="#000000" alink="#000000">
<font face="Verdana, sans-serif" size="2"><p align="center"><b><font size="5">UserGuide - Displaying text output (Console)</font></b></p>

In the previous topic <a href="ug_inputoutput.html">Input & Output</a> you already saw 
an overview about the different possibilities to output text to the user, and in the 
topic <a href="ug_data.html">Storing Data in Memory</a>, we started to build a small 
application to display the properties of files in a particular folder to the 
<a href="debugger.html">debug window</a>. 
<br>
<br>
Now we're going to revisit this example to improve the data output section to resolve 
some issues with using the debug window. Firstly, this window is only available in the 
PureBasic IDE which means its only useful to programmers, secondly it doesn't really 
give us much control over how our output looks. 
<br>
<br>
PureBasic provides a text mode window, or <a href="../console/openconsole.html">console window</a>, 
which can be used in compiled programs. So let's update our example to use it instead. 
<br>
<br>
First, we will need some extra working variables to make this work properly. Amend the 
variable definitions like this: 
<pre><font face="Courier New, Courier, mono"size="2">  ...
  
  <font color="#3A3966">; Now we define a new list of files using the structure previously specified </font>
  <b><font color="#3A3966">NewList</font></b> <font color="#3A3966">Files</font>.FILEITEM()
  <b><font color="#3A3966">Define</font></b>.s Access, Attrib, Create, Folder, Modify, Msg, Num, Size
  <b><font color="#3A3966">Define</font></b>.l Result
  
  ...
</font></pre>

Next, remove the output section of code completely, from the comment line: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; If there are some entries in the list, show the results in the debug window.</font>
  ...
</font></pre>

Now replace this with: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#3A3966">; Open a text mode screen to show the results.</font>
<font color="#3A3966">  OpenConsole</font>()
  
  <font color="#3A3966">; Display a title.</font>
  <font color="#3A3966">; PrintN displays the string given in the console window and moves the print position to the start of the next line afterwards.</font>
  <font color="#3A3966">; Space(n) returns n spaces in a string.</font>
<font color="#3A3966">  PrintN</font>(&quot;File list of &quot; + Folder + &quot;.&quot;)
<font color="#3A3966">  PrintN</font>(&quot;-------------------------------------------------------------------------------&quot;)
  Msg = &quot;Num Name&quot;
<font color="#3A3966">  PrintN</font>(Msg)
  Msg =<font color="#3A3966"> Space</font>(4) + &quot;Create&quot; +<font color="#3A3966"> Space</font>(5) + &quot;Access&quot; +<font color="#3A3966"> Space</font>(5) + &quot;Modify&quot; +<font color="#3A3966"> Space</font>(5) + &quot;Attrib Size&quot;
<font color="#3A3966">  PrintN</font>(Msg)
  
  <font color="#3A3966">; Loop through the list to display the results.</font>
  <b><font color="#3A3966">ForEach</font></b> <font color="#3A3966">Files</font>()
    
    <font color="#3A3966">; Tabulate the number of the list index.</font>
    <font color="#3A3966">; ListIndex() returns the current position in the list, counting from zero.</font>
    <font color="#3A3966">; StrU converts an unsigned number into a string.</font>
    <font color="#3A3966">; RSet pads a string to a set length with the necessary number of a specified character at the front.</font>
    <font color="#3A3966">; Here we use it to make sure all the index numbers are padded to 3 characters in length.</font>
    Num =<font color="#3A3966"> RSet</font>(<font color="#3A3966">StrU</font>(<font color="#3A3966">ListIndex</font>(<font color="#3A3966">Files</font>()) + 1), 3, &quot; &quot;)
    
    <font color="#3A3966">; Display the item number and file name.</font>
    Msg = Num + &quot; &quot; +<font color="#3A3966"> Files</font>()\Name
<font color="#3A3966">    PrintN</font>(Msg)
    
    <font color="#3A3966">; These lines convert the three date values to something more familiar.</font>
    Create =<font color="#3A3966"> FormatDate</font>(&quot;%dd/%mm/%yyyy&quot;,<font color="#3A3966"> Files</font>()\DateCreated)
    Access =<font color="#3A3966"> FormatDate</font>(&quot;%dd/%mm/%yyyy&quot;,<font color="#3A3966"> Files</font>()\DateAccessed)
    Modify =<font color="#3A3966"> FormatDate</font>(&quot;%dd/%mm/%yyyy&quot;,<font color="#3A3966"> Files</font>()\DateModified)
    
    <font color="#3A3966">; Convert the file size to a padded string the same as with the index value above,</font>
    <font color="#3A3966">; but allow space for the maximum size of a quad.</font>
    Size =<font color="#3A3966"> RSet</font>(<font color="#3A3966">StrU</font>(<font color="#3A3966">Files</font>()\Size), 19)
    
    <font color="#3A3966">; Convert the attributes to a string, for now.</font>
    Attrib =<font color="#3A3966"> RSet</font>(<font color="#3A3966">StrU</font>(<font color="#3A3966">Files</font>()\Attributes), 6, &quot; &quot;)
    
    <font color="#3A3966">; Display the file's properties.</font>
    Msg =<font color="#3A3966"> Space</font>(4) + Create + &quot; &quot; + Access + &quot; &quot; + Modify + &quot; &quot; + Attrib + &quot; &quot; + Size
<font color="#3A3966">    PrintN</font>(Msg)
    
    <font color="#3A3966">; Display a blank line.</font>
<font color="#3A3966">    PrintN</font>(&quot;&quot;)
    
  <b><font color="#3A3966">Next</font></b> <font color="#3A3966">Files</font>()
  
  <font color="#3A3966">; Wait for the return key to be displayed, so the results can be viewed before the screen closes.</font>
<font color="#3A3966">  PrintN</font>(&quot;&quot;)
<font color="#3A3966">  PrintN</font>(&quot;Press return to exit&quot;)
<font color="#3A3966">  Input</font>()
</font></pre>

All being well the output should appear in a console window looking something like this: 
<pre><font face="Courier New, Courier, mono"size="2">  File <b><font color="#3A3966">List</font></b> of C:\Documents <b><font color="#3A3966">And</font></b> Settings\user\.
  -------------------------------------------------------------------------------
  Num Name
      Create     Access     Modify     Attrib Size
    1 NTUSER.DAT
      03/07/2008 04/04/2011 02/04/2011     34            18874368
  
    2 kunzip.dll
      14/07/2008 04/04/2011 14/07/2008     32               18432
  
    3 ntuser.dat.LOG
      03/07/2008 04/04/2011 04/04/2011     34                1024
  
    4 ntuser.ini
      03/07/2008 02/04/2011 02/04/2011      6                 278
  
  Press <b><font color="#3A3966">Return</font></b> <b><font color="#3A3966">To</font></b> exit
</font></pre>

This output is from a Windows XP system, later versions of Windows and Linux or Mac OSX 
will show different files of course. 
<br>
<b>Note for Linux/MacOS:</b> Please note, to select &quot;Console&quot; as executable format in the 
<a href="ide_compiler.html">compiler options</a>. 


<p><b>UserGuide Navigation</b></p><blockquote>

<a href="ug_inputoutput.html">< Previous: Input & Output</a> | <a href="ug_overview.html">Overview</a> | <a href="ug_gui.html">Next: Building a graphical user interface (GUI) ></a> 
</body></html>